package Leetcode.array;

import java.util.*;

public class Isvalidshudu {
    public boolean isValidSudoku(char[][] board) {
        for(int i=0;i<9;i++){
            Set<Character> rowSet = new HashSet<>();
            Set<Character> colSet = new HashSet<>();
            for(int j =0;j<9;j++){
                if(board[i][j]!='.'&&!rowSet.add(board[i][j]))
                    return false;
                if(board[j][i]!='.'&&!colSet.add(board[j][i]))
                    return false;
                if(i%3==0&&j%3==0){
                    if(!checkCube(board,i,j))
                        return false;
                }
            }
        }
        return true;

    }
    public boolean checkCube(char[][] board,int row,int col){
        Set<Character> set = new HashSet<>();
        for(int i=row;i<row+3;i++){
            for(int j=col;j<col+3;j++){
                if(board[i][j]!='.'&&!set.add(board[i][j]))
                    return false;
            }
        }
        return true;
    }


}
